package api.config;

import com.lyx.common.config.SystemConfig;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.mvc.condition.RequestConditionHolder;

import javax.servlet.http.HttpServletRequest;

/**
 * --- Be Humble and Hungry ---
 *
 * @author McMeloxD
 * @date 2024/8/13
 * @desc
 */
public class OpenFeignConfig implements RequestInterceptor {

    // 拦截请求,设置请求头
    @Override
    public void apply(RequestTemplate template) {
        //1.获取
        ServletRequestAttributes attributes=(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request= attributes.getRequest();
        //2.设置
        template.header(SystemConfig.HEADER_TOKEN,request.getHeader(SystemConfig.HEADER_TOKEN));
    }
}
